﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogic;
using JScripter;
using BusinessLogic.Controller;

public partial class AjaxPages_Property_SelectPropertyType : AjaxPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //objLoader.InjectScript(string.Format("$('#{0}').LinkPostH('{1}?ac=p', '#propertytype', '#propertytype');", rbCommercial.ClientID,ResolveUrl("~/AjaxPages/Property/SelectPropertyType.aspx")), this.Page);
        //rbResidential.Attributes.Add("onclick", "");
        if (!rbCommercial.Checked && !rbResidential.Checked)
        {
            rbResidential.Checked = true;
        }
        BindData();
    }

    protected void Commercial_Click(object sender, AjaxControl.AjaxEventArg e)
    {
        BindData();
    }
    protected void Residential_Click(object sender, AjaxControl.AjaxEventArg e)
    {
        BindData();
    }
    private void BindData()
    {
        ddPropertyType.Items.Clear();
        ListItem aa = new ListItem("Select", "0");
        ddPropertyType.Items.Add(aa);
        ddTransactionType.Items.Clear();
        aa = new ListItem("Select", "0");
        ddTransactionType.Items.Add(aa);
         if (rbResidential.Checked)
        {
            BindResidentialData();
        }
        else if (rbCommercial.Checked)
        {
            BindCommercialData();
        }
    }
    private void BindResidentialData()
    {
        new PropertyTypeController().BindPropertyType(ddPropertyType, true,false);
        //ListItem propertyType = new ListItem("Residential Apartment", "1");
        //ddPropertyType.Items.Add(propertyType);
        ListItem aa = new ListItem("Sell", "Sell");
        ddTransactionType.Items.Add(aa);
        aa = new ListItem("Rent", "Rent");
        ddTransactionType.Items.Add(aa);
        aa = new ListItem("PG", "PG");
        ddTransactionType.Items.Add(aa);
    }

    private void BindCommercialData()
    {
        new PropertyTypeController().BindPropertyType(ddPropertyType, false, true);
        ListItem aa = new ListItem("Sell", "Sell");
        ddTransactionType.Items.Add(aa);
        aa = new ListItem("Lease out", "Lease out");
        ddTransactionType.Items.Add(aa);
        
    }
    protected void AdvertiseNow_Click(object sender, AjaxControl.AjaxEventArg e)
    {
        string url = "";
        if (rbResidential.Checked)
        {
            url += "?tp=r";           
        }
        else if (rbCommercial.Checked)
        {
            url += "?tp=c";
        }
        if (HtmlHelper.ControlValue(ddPropertyType.ClientID) != "")
        {
            url += "&ptp=" + HtmlHelper.ControlValue(ddPropertyType.ClientID);
        }
        if (HtmlHelper.ControlValue(ddTransactionType.ClientID) != "")
        {
            url += "&ttp=" + HtmlHelper.ControlValue(ddTransactionType.ClientID);
        }
        objLoader.RedirectPage(ResolveUrl("~/AddProperty.aspx") + url);
    }
}